package com.neusoft.controller;

import com.neusoft.core.CommonResult;
import com.neusoft.core.PointLog;
import com.neusoft.service.PointService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.*;

import java.util.List;

//跨域处理
@RefreshScope
@RestController
@RequestMapping("/PointController")
public class PointController {
    @Autowired
    private PointService pointService;

    @GetMapping("/user/{userId}")
    public CommonResult<List<PointLog>> getAllPointLogsByUserId(@PathVariable String userId) {
        List<PointLog> pointLogs = pointService.getAllPointLogsByUserId(userId);
        return new CommonResult<>(200, "success", pointLogs);
    }

    @GetMapping("/{logId}")
    public CommonResult<PointLog> getPointLogById(@PathVariable Integer logId) {
        PointLog pointLog = pointService.getPointLogById(logId);
        return new CommonResult<>(200, "success", pointLog);
    }

    @PostMapping("/insertLog")
    public CommonResult<Integer> addPointLog(@RequestBody PointLog pointLog) {
        if(pointLog==null)
        {
            return new CommonResult<>(403, "不能插入空记录(10800)", null);
        }
        int result = pointService.addPointLog(pointLog);
        return new CommonResult<>(200, "success", result);
    }

    @DeleteMapping("/{logId}")
    public CommonResult<Integer> deletePointLogById(@PathVariable Integer logId) {
        int result = pointService.deletePointLogById(logId);
        return new CommonResult<>(200, "success", result);
    }
}
